package com.example.myapplication.mainactivity

import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.myapplication.R
import com.example.myapplication.ben.HomeData

internal class HomeRecyclerAdapter(with: Int) : BaseQuickAdapter<HomeData.ListBean, BaseViewHolder>(R.layout.item_home_layout) {
    var with = with
    var index = 0

    override fun convert(holder: BaseViewHolder, item: HomeData.ListBean) {

        holder.setText(R.id.title, item.title)
        val view = holder.getView<ImageView>(R.id.imagLayout);
        val layoutParams = view.layoutParams;
        when (index) {
            0 -> {
                val d = item.thumbWidth / with
                val d1 =   item.thumbHeight/d;
                layoutParams.height = d1.toInt()
                layoutParams.width = with;
                view.layoutParams = layoutParams
            }
            1 -> {
                val d = item.thumbWidth / with
                val d1 = (item.thumbHeight / 3)/d;
                layoutParams.height = d1.toInt()
                layoutParams.width = with / 3;
                view.layoutParams = layoutParams
            }
            2 -> {
                layoutParams.height = with / 3
                layoutParams.width = with / 3;
                view.layoutParams = layoutParams
            }
        }

        Glide.with(context)
                .load(item.thumb)
                .centerCrop()
                .into(view);

    }
}